﻿using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
namespace ModulesToolkit.DataContracts
{
    public interface IEntitySearchResult : IListSource
    {
        int TotalRecords { get; }
    }

    public class EntitySearchResult<T> : IEntitySearchResult
    {
        #region Constructors

        public EntitySearchResult(IEnumerable<T> items, int totalRecords)
        {
            Items = items;
            TotalRecords = totalRecords;
        }

        #endregion Constructors

        #region Properties

        bool IListSource.ContainsListCollection
        {
            get { return false; }
        }

        public IEnumerable<T> Items
        {
            private set;
            get;
        }

        public int TotalRecords
        {
            private set;
            get;
        }

        #endregion Properties

        #region Methods

        IList IListSource.GetList()
        {
            return this.Items as IList;
        }

        public T Single()
        {
            return this.Items.Single();
        }

        public T SingleOrDefault()
        {
            return this.Items.SingleOrDefault();
        }

        #endregion Methods

        public int lenght { get; set; }
    }
}